package ru.incoremedia.gwttest.application.client.component;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.rpcforms.client.component.ExtendedRichTextArea;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import ru.incoremedia.gwttest.application.client.i18n.I18N;
import ru.incoremedia.gwttest.core.client.util.AsyncUtils;
import ru.incoremedia.gwttest.core.client.form.MySubmitForm;


public class PostFormPanel extends Composite {

    private VerticalPanel verticalPanel;

    private ExtendedRichTextArea textArea;

    private Label label;

    private Label errorLabel;

    private Button submitButton;

    public static final String POST_FORM_CONTROLLER = "postFormController";

    public static final String TEXT_AREA = "textArea";

    public PostFormPanel() {

        verticalPanel = new VerticalPanel();

        label = new Label(I18N.constants.enterValidStupidText());
        label.addStyleName("smallLabelLight");
        verticalPanel.add(label);

        textArea = new ExtendedRichTextArea();
        textArea.setName(TEXT_AREA);
        textArea.setSize("320px", "240px");
        verticalPanel.add(textArea);
        
        errorLabel = new Label();
        errorLabel.addStyleName("errorLabel");
        verticalPanel.add(errorLabel);

        submitButton = new Button(I18N.constants.submit());
        submitButton.addStyleName("mediumLabelDark");
        verticalPanel.add(submitButton);

        initWidget(verticalPanel);

        final MySubmitForm extendedSubmitForm = new MySubmitForm(POST_FORM_CONTROLLER);
        extendedSubmitForm.addAndBind(textArea, errorLabel);

        submitButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
//                extendedSubmitForm.submit(new AsyncUtils<Boolean>() {
//                    @Override
//                    public void onSucess(Boolean result) {
//                        Window.alert(I18N.constants.ok());
//                    }
//                });
            }
        });
    }

}
